package com.elsa.smart_buffet.service.impl;

import com.elsa.smart_buffet.mapper.YearMapper;
import com.elsa.smart_buffet.pojo.ResultBox.CallBackMessage;
import com.elsa.smart_buffet.pojo.ResultBox.ResponseResult;
import com.elsa.smart_buffet.pojo.Year;
import com.elsa.smart_buffet.service.YearService;
import com.elsa.smart_buffet.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName : YearServiceImpl  //类名
 * @Author : elsa //作者
 */
@Service
@Transactional
public class YearServiceImpl implements YearService {

    @Autowired
    private YearMapper yearMapper;

    @Autowired
    private TimeUtil timeUtil;

    @Override
    public ResponseResult getYearIncome() {
        int year = timeUtil.getYearTime();
        return new ResponseResult(CallBackMessage.SUCCESS, yearMapper.selectById(year));
    }

    @Override
    public ResponseResult getTotalIncome() {
        List<Year> year = yearMapper.selectList(null);
        int totalPrice = 0;
        for(int i = 0; i < year.size(); i++) {
            totalPrice += year.get(i).getYIncome();
        }
        return new ResponseResult(CallBackMessage.SUCCESS, totalPrice);
    }
}
